import request from '@/utils/request';
// 登录 gspswitch
export function login(params) {
    return request.post('/service/user/login.json', params);
}

// 单位信息地图
export async function getUnitMap(params) {
    return await request.post(
        '/service/page/scene.json?',
        {name: params.name},
        {
            params: {
                paged: params.paged,
                pageSize: params.pageSize,
            },
        }
    );
}
//获取设备数据
export async function getEquipmentMap(params) {
    return await request.post(
        '/service/page/node.json?paged=1',
        {
            scene_id: params.scene_id,
            name: params.name,
        },
        {
            params: {
                paged: params.paged,
                pageSize: params.pageSize,
            },
        }
    );
}

//获取传感器接口
export function sensor() {
    return request.post(
        '/service/page/node/sensor/list.json',
        {scene_id: '30', node_data_type: '0', device_code: 'gpsswitch0001'},
        {
            params: {
                paged: 1,
                pageSize: 3,
            },
        }
    );
}

//在线设备根据iot_node_status判断设备是在线还是离线（17是离线，16是在线）
export function onlineUnit() {
    return request.post(
        '/service/page/node.json',
        {},
        {
            params: {
                paged: 1,
            },
        }
    );
}

//实时监控
export function facilityTab(val) {
    return request.post(`/service/page/scene.json?paged=1&pageSize=${val}`, {name: ''});
}

export function facilityData(id, paged, size, query) {
    return request.post(
        `/service/page/node.json`,
        {
            scene_id: id,
            name: query,
        },
        {
            params: {
                paged: paged,
                pageSize: size,
            },
        }
    );
}

export function getEquipmentList(id, paged, size) {
    return request.post(
        `/service/page/node.json`,
        {scene_id: id},
        {
            params: {
                paged: paged,
                pageSize: size,
            },
        }
    );
}

// 获取设备数据接口
export function updateUser() {
    return request.post(
        '/service/page/scene.json',
        {scene_id: '29'},
        {
            params: {
                pageSize: 3,
                paged: 1,
            },
        }
    );
}

//用户信息-个人信息-修改
export function updatePhone(val) {
    return request.put('/service/user/self.json', val);
}

//用户信息-修改密码
export function updateCipher(val) {
    return request.put('/service/user/modify/password.json', {...val});
}
//用户信息-子账户列表
export function facilityList(val, paged) {
    return request.post(`/service/page/user.json?paged=${paged}&pageSize=10`, val);
}
//用户信息-查询
export function facilityQuery(val) {
    return request.post(`/service/page/user.json?paged=1&pageSize=10`, val);
}
//用户信息-新增
export function facilityAdd(val) {
    return request.post(`/service/user/info.json`, val);
}
export function facilityAdd1(val) {
    return request.put(`/service/user/info.json`, val);
}
//用户信息-删除
export function facilityDelete(id) {
    return request.delete(`/service/user/info.json?id=${id}`);
}

//单位管理-新增单位
export function addUnit(val) {
    return request.post('/service/scene.json', val);
}

//单位管理-删除单位
export function delectUnit(id) {
    return request.delete(`/service/scene.json?id=${id}`);
}

//单位管理-编辑单位
export function editUnit(val) {
    return request.put('/service/scene.json', val);
}

//设备管理-新增设备
export function addEquipment(val) {
    return request.post('/service/node.json', {
        ...val,
        lonLat: '120.458179,31.317421',
    });
}

//设备管理删除设备
export function deleteEquipment(id) {
    return request.delete(`/service/node.json?id=${id}`);
}

//设备管理-编辑设备
export function editEquipment(val) {
    return request.put('/service/node.json', val);
}

//归属单位
export function unitList(id) {
    return request.post('/service/relation/scene/user.json', id);
}

//图片列表
export function imgList(id, val) {
    return request.post(`/service/page/fileInfo.json?paged=${val}`, id);
}

//删除图片
export function imgDelete(id) {
    return request.delete(`/service/fileInfo.json?id=${id}`);
}
